package com.ewanghuiju.app.presenter.home;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.home.SearchShopResultContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.PintuanShopListResponBean;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class 搜索商品结果
 * @time 2020/2/16
 */
public class SearchShopResultPresenter extends RxPresenter<SearchShopResultContract.View> implements SearchShopResultContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public SearchShopResultPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getdata(int page, String name, String spe_price, String sales, String people_number) {

        addSubscribe(mDataManager.getPintuansearch(page, name, spe_price, sales, people_number)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<PintuanShopListResponBean>>(mView) {
                    @Override
                    public void onNext(Optional<PintuanShopListResponBean> optional) {
                        if (mView != null)
                            mView.showContent(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        if (mView != null)
                            mView.showErrorContent();
                    }
                })
        );

    }
}
